<?php


namespace app\api\controller;


use logicmodel\GoodsLogic;
use think\Controller;
use think\Request;

class Goods extends Controller
{
    private $goodsLogic;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->goodsLogic = new GoodsLogic();
    }

    /**
     * 搜索
     * @param $search
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function search($search=''){
        return json($this->goodsLogic->search($search));
    }

    /**
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function goodsCategory(){
        return json($this->goodsLogic->goodsCategory());
    }
    /**
     * 作品分类管理
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function goodsCategoryList(){
        return json($this->goodsLogic->goodsCategoryList());
    }
    /**
     * 商品列表
     * @param string $goods_id
     * @param string $author_id
     * @param int $goods_category_id
     * @param int $page
     * @param int $pagesize
     * @param $time_order
     * @param $price_order
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function goodsList($goods_id='',$author_id='',$time_order=1,$price_order=1,$goods_category_id=1,$page=1,$pagesize=10){
        return json($this->goodsLogic->goodsList($goods_id,$author_id,$time_order,$price_order,$goods_category_id,$page,$pagesize));
    }

    /**
     * 积分商品列表
     * @param int $page
     * @param int $pagesize
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function integralGoodsList($page=1,$pagesize=10){
        return json($this->goodsLogic->integralGoodsList($page,$pagesize));
    }
    /**
     * 商品详情
     * @param $id
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function  goodsDetail($id){
        return json($this->goodsLogic->goodsDetail($id));
    }

    /**
     * 交易记录
     * @param $goods_id
     * @param $page
     * @param $pagesize
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function ordersRecord($goods_id,$page=1,$pagesize=10){
        return json($this->goodsLogic->ordersRecord($goods_id,$page,$pagesize));
    }
    /**
     * 商品列表
     * @param $goods_id
     * @param string $users_goods_id
     * @param int $page
     * @param int $pagesize
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function tradeRecord($goods_id,$users_goods_id='',$page=1,$pagesize=10){
        return json($this->goodsLogic->tradeRecord($goods_id,$users_goods_id,$page,$pagesize));
    }
}